#include "Button.h"
#include "../../ImageManager.h"

extern bool Collision(const core::Rectangle& a, const core::Rectangle&b);

namespace PickinOpenSticks {
    namespace Ui {

        void Button::SetDefaultImage() {
            sprite.SetImage(ImageManager::GetSingleton().GetImage("assets/gfx/but1.png", "default_but_active"));
            inactiveSprite.SetImage(ImageManager::GetSingleton().GetImage("assets/gfx/but2.PNG", "default_but_inactive"));

            Resize(75, 50);

        }

        void Button::SetActiveImage(const std::string& filename) {
            sprite.SetImage(ImageManager::GetSingleton().GetImage(filename, filename));
            pos.w = sprite.GetSize().x;
            pos.h = sprite.GetSize().y;
        }

        void Button::SetInactiveImage(const std::string& filename) {
            inactiveSprite.SetImage(ImageManager::GetSingleton().GetImage(filename, filename));
        }

        void Button::Draw(sf::RenderTarget* target) {
            if (!visible) return;

            if (active) target->Draw(sprite);
            else target->Draw(inactiveSprite);

            target->Draw(text);
        }

        void Button::OnClickPressed(sf::Event* event, bool collided) {
            //debug
            Widget::OnClickPressed(event);
            //it was clicked
            active = false;
        }

        void Button::OnClickReleased(sf::Event* event, bool collided) {
            if (collided)
                Widget::OnClickReleased(event);

            //it was released
            active = true;

            /*
            if(Collision(core::Rectangle(event->MouseButton.X,event->MouseButton.Y,2,2),this->pos)) {
                    //do stuff ? this is for debug!
            }
             */

        }
    }
}
